package com.main.controller;

import com.alibaba.fastjson.JSONObject;
import com.main.entity.User;
import com.main.service.UserService;
import com.main.utils.GetUUIDUtil;
import com.main.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author lyl
 * @version 1.0
 * @date 2019/5/21
 */
@Controller
@ResponseBody
@RequestMapping("/user")
@Api(tags = "用户相关")
public class UserController extends AbstractController {
    @Autowired
    private UserService userService;

    @RequestMapping(value = "/userList", produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "获取用户列表")
    public R getUserList() {
        try {
            Thread.sleep(8000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        List<User> userList = userService.getUserList();
        logger.info("userList" + JSONObject.toJSONString(userList));
        return R.ok().put("userList", userList);
    }

    @RequestMapping("/registerUser")
    @ApiOperation(value = "注册用户")
    public R registerUser() {
        User user = new User();
        user.setId(Long.valueOf(GetUUIDUtil.getId()));
        user.setUserName("测试");
        user.setPassword("123456");
        user.setSex("男");
        int num = userService.register(user);
        logger.info("num" + num);
        return R.ok().put("num", num);
    }
}
